package instrarbre;

import exprarbre.ASAExpr;
import java.util.HashMap;
import javax.swing.JTextArea;

public class ASAPrint extends ASAInstr {

    private ASAExpr expression;
    private String chaine = "\"\"";
    private JTextArea area;

    public ASAPrint() {
    }

    public ASAPrint(ASAExpr expression) {
        this.expression = expression;
    }

    public ASAPrint(String chaine) {
        this.chaine = chaine;
    }

    @Override
    public void setView(JTextArea area) {
        this.area = area;
    }

    @Override
    public void interpreter(HashMap<String, Integer> affectation) {
        if (expression != null) {
            area.append(Integer.toString(expression.evalue(affectation)));
        }
        else {
            area.append(chaine.substring(1, chaine.length() - 1).replace("\\n", "\n").replace("\\t", "\t"));
        }
    }
}